<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $table = 'mckj_order';

    protected $fillable = ['userId', 'sn'];

    const CREATED_AT = 'addTime';

    const UPDATED_AT = null;

    protected $dateFormat = 'U';

    const PAY_STATE_NOT_PAY = 0;
    const PAY_STATE_PAID = 2;

    const TYPE_WASH_CAR_NORMAL = 1;
    const TYPE_BUY_CARD = 2;
    const TYPE_WASH_CAR_CARD = 3;
    const TYPE_WASH_CAR_TICKET = 4;


    public static $payStateText = [
        self::PAY_STATE_NOT_PAY => '未支付',
        self::PAY_STATE_PAID => '已支付',
    ];

    public static $typeText = [
        self::TYPE_WASH_CAR_NORMAL => '普通洗车订单',
        self::TYPE_BUY_CARD => '购买卡订单',
        self::TYPE_WASH_CAR_CARD => '卡洗车订单',
        self::TYPE_WASH_CAR_TICKET => '优惠券洗车',
    ];


    public function user()
    {
        return $this->belongsTo(User::class, "userId");
    }

    public function carbarn()
    {
        return $this->belongsTo(Carbarn::class, 'carbarnId');
    }

    public function station()
    {
        return $this->belongsTo(Station::class, "mcstationId");
    }

    public function getPayStateTextAttribute()
    {
        return self::$payStateText[$this->payState] ?? "";
    }

    public function getTypeTextAttribute()
    {
        return self::$typeText[$this->type] ?? "";
    }

    public function isPaid()
    {
        return $this->payState == self::PAY_STATE_PAID;
    }
}
